package com.addplus.townmall.server.api.mapper.authority;

import com.addplus.townmall.server.api.model.authority.MenuFunction;
import com.addplus.townmall.server.api.model.authority.ext.MenuRoleExt;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface MenuFunctionMapper extends BaseAddMapper<MenuFunction> {

    @Select("SELECT id, name,icon, m_desc, dept, url, pid, sort, is_delete, path, gmt_create, gmt_modified,modify_user FROM menu_function WHERE menu_function.is_delete=0 AND FIND_IN_SET(#{id},menu_function.path) ORDER BY menu_function.dept desc,menu_function.sort desc")
    List<MenuFunction> selectMenuFunctionTreeById(@Param("id") Integer id);

    @Select("SELECT id, name,icon, m_desc, dept, url, pid,sort, is_delete, path, gmt_create, gmt_modified,modify_user FROM menu_function WHERE menu_function.is_delete=0 AND menu_function.pid= -1 ORDER BY menu_function.dept desc,menu_function.sort desc")
    List<MenuFunction> selectMenuFunctionOrderSort(Page page);

    List<MenuFunction> getMenuFunctionUserAll(@Param("roles") List<Integer> roles);

    @Select("SELECT id FROM menu_function where FIND_IN_SET(#{id},menu_function.path) AND is_delete = 0")
    List<Integer> getMenuFunctionChilders(@Param("id") Integer id);

    @Update("UPDATE menu_function set is_delete =1 where FIND_IN_SET(#{id},menu_function.path) AND is_delete =0")
    Integer updateLogicallyDeleteChilders(@Param("id") Integer id);

    List<MenuRoleExt> getMenuFunctionRoleAll();

    List<MenuFunction> searchMenuFunctionByName(Page page, @Param("pid") String pid, @Param("name") String name);


}